﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ThermoGroupSample
{
    delegate void UpdateControlDelegate(Control control, string text, Color color);
    public class UIUpdate
    {
        public static RichTextBox richTextBox;

        /// <summary>
        /// 跨线程更新UI
        /// </summary>
        /// <param name="control"></param>
        /// <param name="text"></param>
        /// <param name="color"></param>
        public static void UpdateControl(Control control, string text, Color color)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(new UpdateControlDelegate(UpdateControl), new object[] { control, text, color });
            }
            else
            {
                if (control is RichTextBox)
                {
                    RichTextBox r = control as RichTextBox;
                    StaticMethods.AppendTextColorful(r, text, color);
                }
                else
                {
                    control.Text = text;
                }
            }
        }

    }
}
